<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      header {
        width: 100%;
        height: 60px;
        border-bottom: 1px solid #000;
        font-size: 20px;
        text-align: center;
        line-height: 60px;
      }

      footer {
        position: fixed;
        width: 100%;
        height: 50px;
        bottom: 0;
        left: 0;
        border-top: 1px solid #000;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
      }

      li {
        width: 345px;
        height: 150px;
        border: 1px solid #000;
        margin: 15px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <blog></blog>
    </div>

    <script src="../Vue.js"></script>
    <script>
      // 头部组件
      Vue.component("blog-header", {
        props: ["title"],
        data() {
          return {
            size: 16,
          };
        },
        template: `
          <header>{{ title }} <span @click="fn">+</span></header>
        `,
        methods: {
          fn() {
            this.size++;
            this.$emit("getsize", this.size);
          },
        },
      });

      // 列表的item组件
      Vue.component("blog-list-item", {
        props: ["title", "content"],
        template: `
          <li>
            <h3>{{ title }}</h3>
            <p>{{ content }}</p>
            <button>点赞</button>
          </li>
        `,
      });

      // 列表组件
      Vue.component("blog-list", {
        props: ["list"],
        template: `
          <ul>
            <blog-list-item
              v-for="item in list"
              :key="item.id"
              :title="item.title"
              :content="item.content"
            ></blog-list-item>
          </ul>
        `,
      });

      // 底部的form组件
      Vue.component("blog-form", {
        template: `
          <footer>
            <input type="text" />
            <button>发布</button>
          </footer>
        `,
      });

      Vue.component("blog", {
        data() {
          return {
            size: 16,
            list: [
              {
                id: 1,
                title: "绿水青山就是金山银山",
                content: "接续百年奋斗",
              },
              {
                id: 2,
                title: "上海好邻居",
                content: "不仅是邻居",
              },
              {
                id: 3,
                title: "新疆库车旅游:",
                content: "蓄力求变 突破自我",
              },
            ],
          };
        },
        template: `
          <div :style="{fontSize: size + 'px'}">
            <blog-header title="微博首页" @getsize="getsize"></blog-header>
            <blog-list :list="list"></blog-list>
            <blog-form></blog-form>
          </div>
        `,
        methods: {
          getsize(size) {
            this.size = size;
          },
        },
      });

      new Vue({
        el: "#app",
        data: {},
      });
    </script>
  </body>
</html>
